// $ANTLR 3.1.2 AmFmOptimizer.g 2009-05-11 14:39:33

/*
 * Copyright 2009, Team Mondegreen:
 * Brian Hsieh - bh2181@columbia.edu
 * Eugene Yao - eyy2102@columbia.edu
 * Jake Amonette - jaa2149@columbia.edu
 * Tal Giat - tg2235@colubia.edu
 * 
 * This file is part of AMFM (A Minimal Fractal Music Language), a language created for
 * fractal music as part of the Programming Languages and Translator class at Columbia university.
 *
 * For more details go to: http://code.google.com/p/amfm/
 * 
 * AMFM is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * at your option any later version.
 * 
 * AMFM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with AMFM.  If not, see <http://www.gnu.org/licenses/>. 
 */

package org.mondegreen.amfm.compiler;

import java.util.Set;


import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;import java.util.Stack;
import java.util.List;
import java.util.ArrayList;


/** 
 * AST walker that creates a new AST that doesn't contain seeds that are not used,
 * and does semantic validation such as detecting seeds that are not 4/4 length.
 *
 * @author talgiat
 */
@SuppressWarnings("all")
public class AmFmOptimizer extends TreeParser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "PROGRAM", "DEF", "NOTEUNIT", "NOTE", "ID", "INSTRUMENT", "REST", "FRACTION", "VOLUME_LEVELS_MINUS_F", "NOTELETTERS_WITH_ACCIDENTAL_MINUS_F", "ACCIDENTAL", "ONE_TO_NINE", "START", "PLAY", "SS_PITCH", "SS_VOLUME", "SS_RHYTHM", "SS_PITCH_VOLUME", "SS_PITCH_RHYTHM", "SS_RHYTHM_VOLUME", "SS_ALL", "BOOLEAN", "TEN_AND_UP", "COMMENT", "WS", "'seed'", "'{'", "';'", "'}'", "','", "'F'", "'('", "')'"
    };
    public static final int ONE_TO_NINE=15;
    public static final int SS_PITCH=18;
    public static final int SS_RHYTHM=20;
    public static final int T__29=29;
    public static final int DEF=5;
    public static final int REST=10;
    public static final int SS_ALL=24;
    public static final int ACCIDENTAL=14;
    public static final int SS_RHYTHM_VOLUME=23;
    public static final int SS_PITCH_VOLUME=21;
    public static final int ID=8;
    public static final int INSTRUMENT=9;
    public static final int EOF=-1;
    public static final int TEN_AND_UP=26;
    public static final int NOTELETTERS_WITH_ACCIDENTAL_MINUS_F=13;
    public static final int NOTEUNIT=6;
    public static final int SS_VOLUME=19;
    public static final int T__30=30;
    public static final int SS_PITCH_RHYTHM=22;
    public static final int T__31=31;
    public static final int T__32=32;
    public static final int T__33=33;
    public static final int BOOLEAN=25;
    public static final int WS=28;
    public static final int T__34=34;
    public static final int T__35=35;
    public static final int T__36=36;
    public static final int NOTE=7;
    public static final int START=16;
    public static final int PROGRAM=4;
    public static final int VOLUME_LEVELS_MINUS_F=12;
    public static final int FRACTION=11;
    public static final int COMMENT=27;
    public static final int PLAY=17;

    // delegates
    // delegators


        public AmFmOptimizer(TreeNodeStream input) {
            this(input, new RecognizerSharedState());
        }
        public AmFmOptimizer(TreeNodeStream input, RecognizerSharedState state) {
            super(input, state);
             
        }
        
    protected TreeAdaptor adaptor = new CommonTreeAdaptor();

    public void setTreeAdaptor(TreeAdaptor adaptor) {
        this.adaptor = adaptor;
    }
    public TreeAdaptor getTreeAdaptor() {
        return adaptor;
    }

    public String[] getTokenNames() { return AmFmOptimizer.tokenNames; }
    public String getGrammarFileName() { return "AmFmOptimizer.g"; }


    private Set<String> usedSeeds;

    public void setUsedSeeds(Set<String> usedSeeds) {
      this.usedSeeds = usedSeeds;
    }


    public static class program_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "program"
    // AmFmOptimizer.g:53:1: program : ^( PROGRAM ( seed )+ start_func ) ;
    public final AmFmOptimizer.program_return program() throws RecognitionException {
        AmFmOptimizer.program_return retval = new AmFmOptimizer.program_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree PROGRAM1=null;
        AmFmOptimizer.seed_return seed2 = null;

        AmFmOptimizer.start_func_return start_func3 = null;


        CommonTree PROGRAM1_tree=null;

        try {
            // AmFmOptimizer.g:53:8: ( ^( PROGRAM ( seed )+ start_func ) )
            // AmFmOptimizer.g:53:10: ^( PROGRAM ( seed )+ start_func )
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            {
            CommonTree _save_last_1 = _last;
            CommonTree _first_1 = null;
            CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
            PROGRAM1=(CommonTree)match(input,PROGRAM,FOLLOW_PROGRAM_in_program46); 
            PROGRAM1_tree = (CommonTree)adaptor.dupNode(PROGRAM1);

            root_1 = (CommonTree)adaptor.becomeRoot(PROGRAM1_tree, root_1);



            match(input, Token.DOWN, null); 
            // AmFmOptimizer.g:53:20: ( seed )+
            int cnt1=0;
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( (LA1_0==ID) ) {
                    alt1=1;
                }


                switch (alt1) {
            	case 1 :
            	    // AmFmOptimizer.g:53:20: seed
            	    {
            	    _last = (CommonTree)input.LT(1);
            	    pushFollow(FOLLOW_seed_in_program48);
            	    seed2=seed();

            	    state._fsp--;

            	    adaptor.addChild(root_1, seed2.getTree());

            	    }
            	    break;

            	default :
            	    if ( cnt1 >= 1 ) break loop1;
                        EarlyExitException eee =
                            new EarlyExitException(1, input);
                        throw eee;
                }
                cnt1++;
            } while (true);

            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_start_func_in_program51);
            start_func3=start_func();

            state._fsp--;

            adaptor.addChild(root_1, start_func3.getTree());

            match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
            }


            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "program"

    public static class seed_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "seed"
    // AmFmOptimizer.g:56:1: seed : ^( ID INSTRUMENT ( note_unit )+ ) -> {usedSeeds == null || usedSeeds.contains($ID.text)}? ^( ID INSTRUMENT ( note_unit )+ ) ->;
    public final AmFmOptimizer.seed_return seed() throws RecognitionException {
        AmFmOptimizer.seed_return retval = new AmFmOptimizer.seed_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree ID4=null;
        CommonTree INSTRUMENT5=null;
        AmFmOptimizer.note_unit_return note_unit6 = null;


        CommonTree ID4_tree=null;
        CommonTree INSTRUMENT5_tree=null;
        RewriteRuleNodeStream stream_ID=new RewriteRuleNodeStream(adaptor,"token ID");
        RewriteRuleNodeStream stream_INSTRUMENT=new RewriteRuleNodeStream(adaptor,"token INSTRUMENT");
        RewriteRuleSubtreeStream stream_note_unit=new RewriteRuleSubtreeStream(adaptor,"rule note_unit");
        try {
            // AmFmOptimizer.g:56:7: ( ^( ID INSTRUMENT ( note_unit )+ ) -> {usedSeeds == null || usedSeeds.contains($ID.text)}? ^( ID INSTRUMENT ( note_unit )+ ) ->)
            // AmFmOptimizer.g:56:9: ^( ID INSTRUMENT ( note_unit )+ )
            {
            _last = (CommonTree)input.LT(1);
            {
            CommonTree _save_last_1 = _last;
            CommonTree _first_1 = null;
            CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
            ID4=(CommonTree)match(input,ID,FOLLOW_ID_in_seed63);  
            stream_ID.add(ID4);



            match(input, Token.DOWN, null); 
            _last = (CommonTree)input.LT(1);
            INSTRUMENT5=(CommonTree)match(input,INSTRUMENT,FOLLOW_INSTRUMENT_in_seed65);  
            stream_INSTRUMENT.add(INSTRUMENT5);

            // AmFmOptimizer.g:56:25: ( note_unit )+
            int cnt2=0;
            loop2:
            do {
                int alt2=2;
                int LA2_0 = input.LA(1);

                if ( (LA2_0==NOTEUNIT) ) {
                    alt2=1;
                }


                switch (alt2) {
            	case 1 :
            	    // AmFmOptimizer.g:56:25: note_unit
            	    {
            	    _last = (CommonTree)input.LT(1);
            	    pushFollow(FOLLOW_note_unit_in_seed67);
            	    note_unit6=note_unit();

            	    state._fsp--;

            	    stream_note_unit.add(note_unit6.getTree());

            	    }
            	    break;

            	default :
            	    if ( cnt2 >= 1 ) break loop2;
                        EarlyExitException eee =
                            new EarlyExitException(2, input);
                        throw eee;
                }
                cnt2++;
            } while (true);


            match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
            }



            // AST REWRITE
            // elements: INSTRUMENT, ID, note_unit
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            // wildcard labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"rule retval",retval!=null?retval.tree:null);

            root_0 = (CommonTree)adaptor.nil();
            // 56:37: -> {usedSeeds == null || usedSeeds.contains($ID.text)}? ^( ID INSTRUMENT ( note_unit )+ )
            if (usedSeeds == null || usedSeeds.contains((ID4!=null?ID4.getText():null))) {
                // AmFmOptimizer.g:56:93: ^( ID INSTRUMENT ( note_unit )+ )
                {
                CommonTree root_1 = (CommonTree)adaptor.nil();
                root_1 = (CommonTree)adaptor.becomeRoot(stream_ID.nextNode(), root_1);

                adaptor.addChild(root_1, stream_INSTRUMENT.nextNode());
                if ( !(stream_note_unit.hasNext()) ) {
                    throw new RewriteEarlyExitException();
                }
                while ( stream_note_unit.hasNext() ) {
                    adaptor.addChild(root_1, stream_note_unit.nextTree());

                }
                stream_note_unit.reset();

                adaptor.addChild(root_0, root_1);
                }

            }
            else // 57:30: ->
            {
                root_0 = null;
            }

            retval.tree = root_0;
            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "seed"

    public static class note_unit_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "note_unit"
    // AmFmOptimizer.g:58:1: note_unit : ( ^( NOTEUNIT ^( NOTE note ) ( duration ( volume )? )? ) | ^( NOTEUNIT REST ( duration )? ) );
    public final AmFmOptimizer.note_unit_return note_unit() throws RecognitionException {
        AmFmOptimizer.note_unit_return retval = new AmFmOptimizer.note_unit_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree NOTEUNIT7=null;
        CommonTree NOTE8=null;
        CommonTree NOTEUNIT12=null;
        CommonTree REST13=null;
        AmFmOptimizer.note_return note9 = null;

        AmFmOptimizer.duration_return duration10 = null;

        AmFmOptimizer.volume_return volume11 = null;

        AmFmOptimizer.duration_return duration14 = null;


        CommonTree NOTEUNIT7_tree=null;
        CommonTree NOTE8_tree=null;
        CommonTree NOTEUNIT12_tree=null;
        CommonTree REST13_tree=null;

        try {
            // AmFmOptimizer.g:58:11: ( ^( NOTEUNIT ^( NOTE note ) ( duration ( volume )? )? ) | ^( NOTEUNIT REST ( duration )? ) )
            int alt6=2;
            int LA6_0 = input.LA(1);

            if ( (LA6_0==NOTEUNIT) ) {
                int LA6_1 = input.LA(2);

                if ( (LA6_1==DOWN) ) {
                    int LA6_2 = input.LA(3);

                    if ( (LA6_2==NOTE) ) {
                        alt6=1;
                    }
                    else if ( (LA6_2==REST) ) {
                        alt6=2;
                    }
                    else {
                        NoViableAltException nvae =
                            new NoViableAltException("", 6, 2, input);

                        throw nvae;
                    }
                }
                else {
                    NoViableAltException nvae =
                        new NoViableAltException("", 6, 1, input);

                    throw nvae;
                }
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 6, 0, input);

                throw nvae;
            }
            switch (alt6) {
                case 1 :
                    // AmFmOptimizer.g:58:13: ^( NOTEUNIT ^( NOTE note ) ( duration ( volume )? )? )
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    _last = (CommonTree)input.LT(1);
                    {
                    CommonTree _save_last_1 = _last;
                    CommonTree _first_1 = null;
                    CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
                    NOTEUNIT7=(CommonTree)match(input,NOTEUNIT,FOLLOW_NOTEUNIT_in_note_unit125); 
                    NOTEUNIT7_tree = (CommonTree)adaptor.dupNode(NOTEUNIT7);

                    root_1 = (CommonTree)adaptor.becomeRoot(NOTEUNIT7_tree, root_1);



                    match(input, Token.DOWN, null); 
                    _last = (CommonTree)input.LT(1);
                    {
                    CommonTree _save_last_2 = _last;
                    CommonTree _first_2 = null;
                    CommonTree root_2 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
                    NOTE8=(CommonTree)match(input,NOTE,FOLLOW_NOTE_in_note_unit128); 
                    NOTE8_tree = (CommonTree)adaptor.dupNode(NOTE8);

                    root_2 = (CommonTree)adaptor.becomeRoot(NOTE8_tree, root_2);



                    match(input, Token.DOWN, null); 
                    _last = (CommonTree)input.LT(1);
                    pushFollow(FOLLOW_note_in_note_unit130);
                    note9=note();

                    state._fsp--;

                    adaptor.addChild(root_2, note9.getTree());

                    match(input, Token.UP, null); adaptor.addChild(root_1, root_2);_last = _save_last_2;
                    }

                    // AmFmOptimizer.g:58:37: ( duration ( volume )? )?
                    int alt4=2;
                    int LA4_0 = input.LA(1);

                    if ( (LA4_0==FRACTION||LA4_0==ONE_TO_NINE||LA4_0==TEN_AND_UP) ) {
                        alt4=1;
                    }
                    switch (alt4) {
                        case 1 :
                            // AmFmOptimizer.g:58:38: duration ( volume )?
                            {
                            _last = (CommonTree)input.LT(1);
                            pushFollow(FOLLOW_duration_in_note_unit134);
                            duration10=duration();

                            state._fsp--;

                            adaptor.addChild(root_1, duration10.getTree());
                            // AmFmOptimizer.g:58:47: ( volume )?
                            int alt3=2;
                            int LA3_0 = input.LA(1);

                            if ( (LA3_0==VOLUME_LEVELS_MINUS_F||LA3_0==34) ) {
                                alt3=1;
                            }
                            switch (alt3) {
                                case 1 :
                                    // AmFmOptimizer.g:58:47: volume
                                    {
                                    _last = (CommonTree)input.LT(1);
                                    pushFollow(FOLLOW_volume_in_note_unit136);
                                    volume11=volume();

                                    state._fsp--;

                                    adaptor.addChild(root_1, volume11.getTree());

                                    }
                                    break;

                            }


                            }
                            break;

                    }


                    match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
                    }


                    }
                    break;
                case 2 :
                    // AmFmOptimizer.g:58:60: ^( NOTEUNIT REST ( duration )? )
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    _last = (CommonTree)input.LT(1);
                    {
                    CommonTree _save_last_1 = _last;
                    CommonTree _first_1 = null;
                    CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
                    NOTEUNIT12=(CommonTree)match(input,NOTEUNIT,FOLLOW_NOTEUNIT_in_note_unit145); 
                    NOTEUNIT12_tree = (CommonTree)adaptor.dupNode(NOTEUNIT12);

                    root_1 = (CommonTree)adaptor.becomeRoot(NOTEUNIT12_tree, root_1);



                    match(input, Token.DOWN, null); 
                    _last = (CommonTree)input.LT(1);
                    REST13=(CommonTree)match(input,REST,FOLLOW_REST_in_note_unit147); 
                    REST13_tree = (CommonTree)adaptor.dupNode(REST13);

                    adaptor.addChild(root_1, REST13_tree);

                    // AmFmOptimizer.g:58:76: ( duration )?
                    int alt5=2;
                    int LA5_0 = input.LA(1);

                    if ( (LA5_0==FRACTION||LA5_0==ONE_TO_NINE||LA5_0==TEN_AND_UP) ) {
                        alt5=1;
                    }
                    switch (alt5) {
                        case 1 :
                            // AmFmOptimizer.g:58:76: duration
                            {
                            _last = (CommonTree)input.LT(1);
                            pushFollow(FOLLOW_duration_in_note_unit149);
                            duration14=duration();

                            state._fsp--;

                            adaptor.addChild(root_1, duration14.getTree());

                            }
                            break;

                    }


                    match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
                    }


                    }
                    break;

            }
            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "note_unit"

    public static class duration_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "duration"
    // AmFmOptimizer.g:59:1: duration : ( FRACTION | number );
    public final AmFmOptimizer.duration_return duration() throws RecognitionException {
        AmFmOptimizer.duration_return retval = new AmFmOptimizer.duration_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree FRACTION15=null;
        AmFmOptimizer.number_return number16 = null;


        CommonTree FRACTION15_tree=null;

        try {
            // AmFmOptimizer.g:59:9: ( FRACTION | number )
            int alt7=2;
            int LA7_0 = input.LA(1);

            if ( (LA7_0==FRACTION) ) {
                alt7=1;
            }
            else if ( (LA7_0==ONE_TO_NINE||LA7_0==TEN_AND_UP) ) {
                alt7=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 7, 0, input);

                throw nvae;
            }
            switch (alt7) {
                case 1 :
                    // AmFmOptimizer.g:59:11: FRACTION
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    _last = (CommonTree)input.LT(1);
                    FRACTION15=(CommonTree)match(input,FRACTION,FOLLOW_FRACTION_in_duration157); 
                    FRACTION15_tree = (CommonTree)adaptor.dupNode(FRACTION15);

                    adaptor.addChild(root_0, FRACTION15_tree);


                    }
                    break;
                case 2 :
                    // AmFmOptimizer.g:59:22: number
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    _last = (CommonTree)input.LT(1);
                    pushFollow(FOLLOW_number_in_duration161);
                    number16=number();

                    state._fsp--;

                    adaptor.addChild(root_0, number16.getTree());

                    }
                    break;

            }
            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "duration"

    public static class volume_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "volume"
    // AmFmOptimizer.g:60:1: volume : ( VOLUME_LEVELS_MINUS_F | 'F' );
    public final AmFmOptimizer.volume_return volume() throws RecognitionException {
        AmFmOptimizer.volume_return retval = new AmFmOptimizer.volume_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree set17=null;

        CommonTree set17_tree=null;

        try {
            // AmFmOptimizer.g:60:9: ( VOLUME_LEVELS_MINUS_F | 'F' )
            // AmFmOptimizer.g:
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            set17=(CommonTree)input.LT(1);
            if ( input.LA(1)==VOLUME_LEVELS_MINUS_F||input.LA(1)==34 ) {
                input.consume();

                set17_tree = (CommonTree)adaptor.dupNode(set17);

                adaptor.addChild(root_0, set17_tree);

                state.errorRecovery=false;
            }
            else {
                MismatchedSetException mse = new MismatchedSetException(null,input);
                throw mse;
            }

             

            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "volume"

    public static class note_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "note"
    // AmFmOptimizer.g:61:1: note : note_letter ( octave )? ;
    public final AmFmOptimizer.note_return note() throws RecognitionException {
        AmFmOptimizer.note_return retval = new AmFmOptimizer.note_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        AmFmOptimizer.note_letter_return note_letter18 = null;

        AmFmOptimizer.octave_return octave19 = null;



        try {
            // AmFmOptimizer.g:61:6: ( note_letter ( octave )? )
            // AmFmOptimizer.g:61:9: note_letter ( octave )?
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_note_letter_in_note181);
            note_letter18=note_letter();

            state._fsp--;

            adaptor.addChild(root_0, note_letter18.getTree());
            // AmFmOptimizer.g:61:21: ( octave )?
            int alt8=2;
            int LA8_0 = input.LA(1);

            if ( (LA8_0==ONE_TO_NINE) ) {
                alt8=1;
            }
            switch (alt8) {
                case 1 :
                    // AmFmOptimizer.g:61:21: octave
                    {
                    _last = (CommonTree)input.LT(1);
                    pushFollow(FOLLOW_octave_in_note183);
                    octave19=octave();

                    state._fsp--;

                    adaptor.addChild(root_0, octave19.getTree());

                    }
                    break;

            }


            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "note"

    public static class note_letter_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "note_letter"
    // AmFmOptimizer.g:62:1: note_letter : ( NOTELETTERS_WITH_ACCIDENTAL_MINUS_F | 'F' ( ACCIDENTAL )? );
    public final AmFmOptimizer.note_letter_return note_letter() throws RecognitionException {
        AmFmOptimizer.note_letter_return retval = new AmFmOptimizer.note_letter_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree NOTELETTERS_WITH_ACCIDENTAL_MINUS_F20=null;
        CommonTree char_literal21=null;
        CommonTree ACCIDENTAL22=null;

        CommonTree NOTELETTERS_WITH_ACCIDENTAL_MINUS_F20_tree=null;
        CommonTree char_literal21_tree=null;
        CommonTree ACCIDENTAL22_tree=null;

        try {
            // AmFmOptimizer.g:62:12: ( NOTELETTERS_WITH_ACCIDENTAL_MINUS_F | 'F' ( ACCIDENTAL )? )
            int alt10=2;
            int LA10_0 = input.LA(1);

            if ( (LA10_0==NOTELETTERS_WITH_ACCIDENTAL_MINUS_F) ) {
                alt10=1;
            }
            else if ( (LA10_0==34) ) {
                alt10=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 10, 0, input);

                throw nvae;
            }
            switch (alt10) {
                case 1 :
                    // AmFmOptimizer.g:62:14: NOTELETTERS_WITH_ACCIDENTAL_MINUS_F
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    _last = (CommonTree)input.LT(1);
                    NOTELETTERS_WITH_ACCIDENTAL_MINUS_F20=(CommonTree)match(input,NOTELETTERS_WITH_ACCIDENTAL_MINUS_F,FOLLOW_NOTELETTERS_WITH_ACCIDENTAL_MINUS_F_in_note_letter192); 
                    NOTELETTERS_WITH_ACCIDENTAL_MINUS_F20_tree = (CommonTree)adaptor.dupNode(NOTELETTERS_WITH_ACCIDENTAL_MINUS_F20);

                    adaptor.addChild(root_0, NOTELETTERS_WITH_ACCIDENTAL_MINUS_F20_tree);


                    }
                    break;
                case 2 :
                    // AmFmOptimizer.g:62:52: 'F' ( ACCIDENTAL )?
                    {
                    root_0 = (CommonTree)adaptor.nil();

                    _last = (CommonTree)input.LT(1);
                    char_literal21=(CommonTree)match(input,34,FOLLOW_34_in_note_letter196); 
                    char_literal21_tree = (CommonTree)adaptor.dupNode(char_literal21);

                    adaptor.addChild(root_0, char_literal21_tree);

                    // AmFmOptimizer.g:62:55: ( ACCIDENTAL )?
                    int alt9=2;
                    int LA9_0 = input.LA(1);

                    if ( (LA9_0==ACCIDENTAL) ) {
                        alt9=1;
                    }
                    switch (alt9) {
                        case 1 :
                            // AmFmOptimizer.g:62:55: ACCIDENTAL
                            {
                            _last = (CommonTree)input.LT(1);
                            ACCIDENTAL22=(CommonTree)match(input,ACCIDENTAL,FOLLOW_ACCIDENTAL_in_note_letter197); 
                            ACCIDENTAL22_tree = (CommonTree)adaptor.dupNode(ACCIDENTAL22);

                            adaptor.addChild(root_0, ACCIDENTAL22_tree);


                            }
                            break;

                    }


                    }
                    break;

            }
            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "note_letter"

    public static class octave_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "octave"
    // AmFmOptimizer.g:63:1: octave : ONE_TO_NINE ;
    public final AmFmOptimizer.octave_return octave() throws RecognitionException {
        AmFmOptimizer.octave_return retval = new AmFmOptimizer.octave_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree ONE_TO_NINE23=null;

        CommonTree ONE_TO_NINE23_tree=null;

        try {
            // AmFmOptimizer.g:63:7: ( ONE_TO_NINE )
            // AmFmOptimizer.g:63:9: ONE_TO_NINE
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            ONE_TO_NINE23=(CommonTree)match(input,ONE_TO_NINE,FOLLOW_ONE_TO_NINE_in_octave204); 
            ONE_TO_NINE23_tree = (CommonTree)adaptor.dupNode(ONE_TO_NINE23);

            adaptor.addChild(root_0, ONE_TO_NINE23_tree);


            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "octave"

    public static class start_func_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "start_func"
    // AmFmOptimizer.g:66:1: start_func : ^( START ( function )* ) ;
    public final AmFmOptimizer.start_func_return start_func() throws RecognitionException {
        AmFmOptimizer.start_func_return retval = new AmFmOptimizer.start_func_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree START24=null;
        AmFmOptimizer.function_return function25 = null;


        CommonTree START24_tree=null;

        try {
            // AmFmOptimizer.g:66:11: ( ^( START ( function )* ) )
            // AmFmOptimizer.g:66:14: ^( START ( function )* )
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            {
            CommonTree _save_last_1 = _last;
            CommonTree _first_1 = null;
            CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
            START24=(CommonTree)match(input,START,FOLLOW_START_in_start_func214); 
            START24_tree = (CommonTree)adaptor.dupNode(START24);

            root_1 = (CommonTree)adaptor.becomeRoot(START24_tree, root_1);



            if ( input.LA(1)==Token.DOWN ) {
                match(input, Token.DOWN, null); 
                // AmFmOptimizer.g:66:22: ( function )*
                loop11:
                do {
                    int alt11=2;
                    int LA11_0 = input.LA(1);

                    if ( ((LA11_0>=PLAY && LA11_0<=SS_ALL)) ) {
                        alt11=1;
                    }


                    switch (alt11) {
                	case 1 :
                	    // AmFmOptimizer.g:66:22: function
                	    {
                	    _last = (CommonTree)input.LT(1);
                	    pushFollow(FOLLOW_function_in_start_func216);
                	    function25=function();

                	    state._fsp--;

                	    adaptor.addChild(root_1, function25.getTree());

                	    }
                	    break;

                	default :
                	    break loop11;
                    }
                } while (true);


                match(input, Token.UP, null); 
            }adaptor.addChild(root_0, root_1);_last = _save_last_1;
            }


            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "start_func"

    public static class function_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "function"
    // AmFmOptimizer.g:67:1: function : ( play | ss_func ) ;
    public final AmFmOptimizer.function_return function() throws RecognitionException {
        AmFmOptimizer.function_return retval = new AmFmOptimizer.function_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        AmFmOptimizer.play_return play26 = null;

        AmFmOptimizer.ss_func_return ss_func27 = null;



        try {
            // AmFmOptimizer.g:67:9: ( ( play | ss_func ) )
            // AmFmOptimizer.g:67:11: ( play | ss_func )
            {
            root_0 = (CommonTree)adaptor.nil();

            // AmFmOptimizer.g:67:11: ( play | ss_func )
            int alt12=2;
            int LA12_0 = input.LA(1);

            if ( (LA12_0==PLAY) ) {
                alt12=1;
            }
            else if ( ((LA12_0>=SS_PITCH && LA12_0<=SS_ALL)) ) {
                alt12=2;
            }
            else {
                NoViableAltException nvae =
                    new NoViableAltException("", 12, 0, input);

                throw nvae;
            }
            switch (alt12) {
                case 1 :
                    // AmFmOptimizer.g:67:12: play
                    {
                    _last = (CommonTree)input.LT(1);
                    pushFollow(FOLLOW_play_in_function225);
                    play26=play();

                    state._fsp--;

                    adaptor.addChild(root_0, play26.getTree());

                    }
                    break;
                case 2 :
                    // AmFmOptimizer.g:67:19: ss_func
                    {
                    _last = (CommonTree)input.LT(1);
                    pushFollow(FOLLOW_ss_func_in_function229);
                    ss_func27=ss_func();

                    state._fsp--;

                    adaptor.addChild(root_0, ss_func27.getTree());

                    }
                    break;

            }


            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "function"

    public static class play_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "play"
    // AmFmOptimizer.g:68:1: play : ^( PLAY func_params ) ;
    public final AmFmOptimizer.play_return play() throws RecognitionException {
        AmFmOptimizer.play_return retval = new AmFmOptimizer.play_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree PLAY28=null;
        AmFmOptimizer.func_params_return func_params29 = null;


        CommonTree PLAY28_tree=null;

        try {
            // AmFmOptimizer.g:68:5: ( ^( PLAY func_params ) )
            // AmFmOptimizer.g:68:7: ^( PLAY func_params )
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            {
            CommonTree _save_last_1 = _last;
            CommonTree _first_1 = null;
            CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
            PLAY28=(CommonTree)match(input,PLAY,FOLLOW_PLAY_in_play237); 
            PLAY28_tree = (CommonTree)adaptor.dupNode(PLAY28);

            root_1 = (CommonTree)adaptor.becomeRoot(PLAY28_tree, root_1);



            match(input, Token.DOWN, null); 
            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_func_params_in_play239);
            func_params29=func_params();

            state._fsp--;

            adaptor.addChild(root_1, func_params29.getTree());

            match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
            }


            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "play"

    public static class ss_func_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "ss_func"
    // AmFmOptimizer.g:69:1: ss_func : ^( ss_func_name ss_func_params ) ;
    public final AmFmOptimizer.ss_func_return ss_func() throws RecognitionException {
        AmFmOptimizer.ss_func_return retval = new AmFmOptimizer.ss_func_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        AmFmOptimizer.ss_func_name_return ss_func_name30 = null;

        AmFmOptimizer.ss_func_params_return ss_func_params31 = null;



        try {
            // AmFmOptimizer.g:69:8: ( ^( ss_func_name ss_func_params ) )
            // AmFmOptimizer.g:69:10: ^( ss_func_name ss_func_params )
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            {
            CommonTree _save_last_1 = _last;
            CommonTree _first_1 = null;
            CommonTree root_1 = (CommonTree)adaptor.nil();_last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_ss_func_name_in_ss_func247);
            ss_func_name30=ss_func_name();

            state._fsp--;

            root_1 = (CommonTree)adaptor.becomeRoot(ss_func_name30.getTree(), root_1);


            match(input, Token.DOWN, null); 
            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_ss_func_params_in_ss_func249);
            ss_func_params31=ss_func_params();

            state._fsp--;

            adaptor.addChild(root_1, ss_func_params31.getTree());

            match(input, Token.UP, null); adaptor.addChild(root_0, root_1);_last = _save_last_1;
            }


            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "ss_func"

    public static class ss_func_name_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "ss_func_name"
    // AmFmOptimizer.g:70:1: ss_func_name : ( SS_PITCH | SS_VOLUME | SS_RHYTHM | SS_PITCH_VOLUME | SS_PITCH_RHYTHM | SS_RHYTHM_VOLUME | SS_ALL ) ;
    public final AmFmOptimizer.ss_func_name_return ss_func_name() throws RecognitionException {
        AmFmOptimizer.ss_func_name_return retval = new AmFmOptimizer.ss_func_name_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree set32=null;

        CommonTree set32_tree=null;

        try {
            // AmFmOptimizer.g:70:13: ( ( SS_PITCH | SS_VOLUME | SS_RHYTHM | SS_PITCH_VOLUME | SS_PITCH_RHYTHM | SS_RHYTHM_VOLUME | SS_ALL ) )
            // AmFmOptimizer.g:70:15: ( SS_PITCH | SS_VOLUME | SS_RHYTHM | SS_PITCH_VOLUME | SS_PITCH_RHYTHM | SS_RHYTHM_VOLUME | SS_ALL )
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            set32=(CommonTree)input.LT(1);
            if ( (input.LA(1)>=SS_PITCH && input.LA(1)<=SS_ALL) ) {
                input.consume();

                set32_tree = (CommonTree)adaptor.dupNode(set32);

                adaptor.addChild(root_0, set32_tree);

                state.errorRecovery=false;
            }
            else {
                MismatchedSetException mse = new MismatchedSetException(null,input);
                throw mse;
            }


            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "ss_func_name"

    public static class ss_func_params_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "ss_func_params"
    // AmFmOptimizer.g:71:1: ss_func_params : func_params BOOLEAN ;
    public final AmFmOptimizer.ss_func_params_return ss_func_params() throws RecognitionException {
        AmFmOptimizer.ss_func_params_return retval = new AmFmOptimizer.ss_func_params_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree BOOLEAN34=null;
        AmFmOptimizer.func_params_return func_params33 = null;


        CommonTree BOOLEAN34_tree=null;

        try {
            // AmFmOptimizer.g:71:15: ( func_params BOOLEAN )
            // AmFmOptimizer.g:71:17: func_params BOOLEAN
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_func_params_in_ss_func_params288);
            func_params33=func_params();

            state._fsp--;

            adaptor.addChild(root_0, func_params33.getTree());
            _last = (CommonTree)input.LT(1);
            BOOLEAN34=(CommonTree)match(input,BOOLEAN,FOLLOW_BOOLEAN_in_ss_func_params290); 
            BOOLEAN34_tree = (CommonTree)adaptor.dupNode(BOOLEAN34);

            adaptor.addChild(root_0, BOOLEAN34_tree);


            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "ss_func_params"

    public static class func_params_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "func_params"
    // AmFmOptimizer.g:72:1: func_params : ID start_bar num_of_bars ;
    public final AmFmOptimizer.func_params_return func_params() throws RecognitionException {
        AmFmOptimizer.func_params_return retval = new AmFmOptimizer.func_params_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree ID35=null;
        AmFmOptimizer.start_bar_return start_bar36 = null;

        AmFmOptimizer.num_of_bars_return num_of_bars37 = null;


        CommonTree ID35_tree=null;

        try {
            // AmFmOptimizer.g:72:12: ( ID start_bar num_of_bars )
            // AmFmOptimizer.g:72:14: ID start_bar num_of_bars
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            ID35=(CommonTree)match(input,ID,FOLLOW_ID_in_func_params296); 
            ID35_tree = (CommonTree)adaptor.dupNode(ID35);

            adaptor.addChild(root_0, ID35_tree);

            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_start_bar_in_func_params298);
            start_bar36=start_bar();

            state._fsp--;

            adaptor.addChild(root_0, start_bar36.getTree());
            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_num_of_bars_in_func_params300);
            num_of_bars37=num_of_bars();

            state._fsp--;

            adaptor.addChild(root_0, num_of_bars37.getTree());

            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "func_params"

    public static class start_bar_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "start_bar"
    // AmFmOptimizer.g:73:1: start_bar : number ;
    public final AmFmOptimizer.start_bar_return start_bar() throws RecognitionException {
        AmFmOptimizer.start_bar_return retval = new AmFmOptimizer.start_bar_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        AmFmOptimizer.number_return number38 = null;



        try {
            // AmFmOptimizer.g:73:10: ( number )
            // AmFmOptimizer.g:73:12: number
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_number_in_start_bar307);
            number38=number();

            state._fsp--;

            adaptor.addChild(root_0, number38.getTree());

            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "start_bar"

    public static class num_of_bars_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "num_of_bars"
    // AmFmOptimizer.g:74:1: num_of_bars : number ;
    public final AmFmOptimizer.num_of_bars_return num_of_bars() throws RecognitionException {
        AmFmOptimizer.num_of_bars_return retval = new AmFmOptimizer.num_of_bars_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        AmFmOptimizer.number_return number39 = null;



        try {
            // AmFmOptimizer.g:74:12: ( number )
            // AmFmOptimizer.g:74:14: number
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            pushFollow(FOLLOW_number_in_num_of_bars314);
            number39=number();

            state._fsp--;

            adaptor.addChild(root_0, number39.getTree());

            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "num_of_bars"

    public static class number_return extends TreeRuleReturnScope {
        CommonTree tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start "number"
    // AmFmOptimizer.g:75:1: number : ( ONE_TO_NINE | TEN_AND_UP );
    public final AmFmOptimizer.number_return number() throws RecognitionException {
        AmFmOptimizer.number_return retval = new AmFmOptimizer.number_return();
        retval.start = input.LT(1);

        CommonTree root_0 = null;

        CommonTree _first_0 = null;
        CommonTree _last = null;

        CommonTree set40=null;

        CommonTree set40_tree=null;

        try {
            // AmFmOptimizer.g:75:9: ( ONE_TO_NINE | TEN_AND_UP )
            // AmFmOptimizer.g:
            {
            root_0 = (CommonTree)adaptor.nil();

            _last = (CommonTree)input.LT(1);
            set40=(CommonTree)input.LT(1);
            if ( input.LA(1)==ONE_TO_NINE||input.LA(1)==TEN_AND_UP ) {
                input.consume();

                set40_tree = (CommonTree)adaptor.dupNode(set40);

                adaptor.addChild(root_0, set40_tree);

                state.errorRecovery=false;
            }
            else {
                MismatchedSetException mse = new MismatchedSetException(null,input);
                throw mse;
            }

             

            }

            retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
        }
        finally {
        }
        return retval;
    }
    // $ANTLR end "number"

    // Delegated rules


 

    public static final BitSet FOLLOW_PROGRAM_in_program46 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_seed_in_program48 = new BitSet(new long[]{0x0000000000010100L});
    public static final BitSet FOLLOW_start_func_in_program51 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_ID_in_seed63 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_INSTRUMENT_in_seed65 = new BitSet(new long[]{0x0000000000000040L});
    public static final BitSet FOLLOW_note_unit_in_seed67 = new BitSet(new long[]{0x0000000000000048L});
    public static final BitSet FOLLOW_NOTEUNIT_in_note_unit125 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_NOTE_in_note_unit128 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_note_in_note_unit130 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_duration_in_note_unit134 = new BitSet(new long[]{0x0000000400001008L});
    public static final BitSet FOLLOW_volume_in_note_unit136 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_NOTEUNIT_in_note_unit145 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_REST_in_note_unit147 = new BitSet(new long[]{0x0000000004008808L});
    public static final BitSet FOLLOW_duration_in_note_unit149 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_FRACTION_in_duration157 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_number_in_duration161 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_set_in_volume0 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_note_letter_in_note181 = new BitSet(new long[]{0x0000000000008002L});
    public static final BitSet FOLLOW_octave_in_note183 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_NOTELETTERS_WITH_ACCIDENTAL_MINUS_F_in_note_letter192 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_34_in_note_letter196 = new BitSet(new long[]{0x0000000000004002L});
    public static final BitSet FOLLOW_ACCIDENTAL_in_note_letter197 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ONE_TO_NINE_in_octave204 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_START_in_start_func214 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_function_in_start_func216 = new BitSet(new long[]{0x0000000001FE0008L});
    public static final BitSet FOLLOW_play_in_function225 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ss_func_in_function229 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_PLAY_in_play237 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_func_params_in_play239 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_ss_func_name_in_ss_func247 = new BitSet(new long[]{0x0000000000000004L});
    public static final BitSet FOLLOW_ss_func_params_in_ss_func249 = new BitSet(new long[]{0x0000000000000008L});
    public static final BitSet FOLLOW_set_in_ss_func_name256 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_func_params_in_ss_func_params288 = new BitSet(new long[]{0x0000000002000000L});
    public static final BitSet FOLLOW_BOOLEAN_in_ss_func_params290 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_ID_in_func_params296 = new BitSet(new long[]{0x0000000004008800L});
    public static final BitSet FOLLOW_start_bar_in_func_params298 = new BitSet(new long[]{0x0000000004008800L});
    public static final BitSet FOLLOW_num_of_bars_in_func_params300 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_number_in_start_bar307 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_number_in_num_of_bars314 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_set_in_number0 = new BitSet(new long[]{0x0000000000000002L});

}